
"""
  `syllable_count(string, vowels="aeiouy", exceptions=[r"[aeiou]les?\b",r"[^l]e\b"])`

  Counts the syllables in a string.

  The algorithm given simply counts contiguous sequences of vowels, adjusting
  for regex-specified exceptions, which reduce the count by one. Where a string 
  with multiple words is input, the result is the sum for each word. 

  The default arguments for `vowels` and `exceptions` mean that the function 
  gives good output for English text, though certain words like 'Maria' will trip 
  it up. Replacing vowels and rules would allow for the algorithm to apply for other 
  languages. 
  
  The function should always return at least one syllable per word.
"""
function syllable_count(word::Union{String,SubString}, vowels::String="aeiouy", exceptions::Array{Regex,1}=[r"[aeiou][lr]es?\b", r"[^lri]es?\b"])
  
  #Catch sentence input
  if contains(word, " ")
    words = split(word, [' ','-','\n','\t'])
    return sum(map(w -> syllable_count(w, vowels, exceptions), words))  
  end

  #Count vowels.
  word = lowercase(word)
  lc = ' '
  count = 0
  for char in word
    if char in vowels && ! (lc in vowels)
      count += 1
    end
    lc = char
  end     

  #Remove silent endings
  for ex in exceptions
    if ismatch(ex,word) && count > 1
      count -= 1
    end
  end

  return count
end



function time_word(word, language)
    if length(word) == 0 
      return 0
    elseif language == "de"
      return 0.201443 + 0.247255*length(matchall(r"[0-9]{2}", word)) + 0.220354*length(matchall(r"[0-9]", word)) + 0.155791*length(matchall(r"q", word)) + 0.147522*length(matchall(r"x", word)) + 0.141111*length(matchall(r"[0-9]{4}", word)) + 0.111575*length(matchall(r"\u00ee", word)) + 0.109382*length(matchall(r"[^a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fdbcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.099467*length(matchall(r"o", word)) + 0.094990*length(matchall(r"a", word)) + 0.089802*length(matchall(r"z", word)) + 0.088050*length(matchall(r"\u00f3", word)) + 0.080506*length(matchall(r"\u00e1", word)) + 0.079824*length(matchall(r"\u00e2", word)) + 0.078788*length(matchall(r"y", word)) + 0.073479*length(matchall(r"\u00e0", word)) + 0.068338*length(matchall(r"\u00e4", word)) + 0.066598*length(matchall(r"s", word)) + 0.063880*length(matchall(r"\u00ef", word)) + 0.062730*length(matchall(r"i", word)) + 0.061144*length(matchall(r"k", word)) + 0.057448*length(matchall(r"\u00f4", word)) + 0.055320*length(matchall(r"\u00e9", word)) + 0.055251*length(matchall(r"\u00e8", word)) + 0.053560*length(matchall(r"v", word)) + 0.052198*length(matchall(r"\u00ed", word)) + 0.050962*length(matchall(r"\u00ea", word)) + 0.049994*length(matchall(r"b", word)) + 0.049982*length(matchall(r"f", word)) + 0.047746*length(matchall(r"e", word)) + 0.047723*length(matchall(r"^[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd]", word)) + 0.047120*length(matchall(r"j", word)) + 0.046027*length(matchall(r"p", word)) + 0.045183*length(matchall(r"t", word)) + 0.040199*length(matchall(r"r", word)) + 0.039382*length(matchall(r"d", word)) + 0.037563*length(matchall(r"\u00f1", word)) + 0.037290*length(matchall(r"\u00f6", word)) + 0.037290*length(matchall(r"\u00f6", word)) + 0.036302*length(matchall(r"^[bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]{3}", word)) + 0.035693*length(matchall(r"g", word)) + 0.034323*length(matchall(r"\u00fb", word)) + 0.032789*length(matchall(r"u", word)) + 0.032789*length(matchall(r"u", word)) + 0.032587*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd][bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.030861*length(matchall(r"n", word)) + 0.029051*length(matchall(r"m", word)) + 0.027110*length(matchall(r"l", word)) + 0.027075*length(matchall(r"w", word)) + 0.025398*length(matchall(r"h", word)) + 0.023578*length(matchall(r"\u00e7", word)) + 0.013630*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd]\$", word)) + 0.012129*length(matchall(r"c", word)) + 0.002293*length(matchall(r"\u00eb", word)) 
    elseif language == "en-US"
      return 0.288128 + 0.954096*length(matchall(r"[0-9]{4}", word)) + 0.356994*length(matchall(r"[0-9]", word)) + 0.289716*length(matchall(r"\u0169", word)) + 0.260762*length(matchall(r"^[bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]{3}", word)) + 0.202507*length(matchall(r"\u00f1", word)) + 0.189280*length(matchall(r"q", word)) + 0.172014*length(matchall(r"x", word)) + 0.138827*length(matchall(r"n", word)) + 0.132514*length(matchall(r"m", word)) + 0.128558*length(matchall(r"\u012b", word)) + 0.117963*length(matchall(r"d", word)) + 0.115260*length(matchall(r"\u00ed", word)) + 0.111563*length(matchall(r"b", word)) + 0.109092*length(matchall(r"v", word)) + 0.107073*length(matchall(r"\u00e7", word)) + 0.105800*length(matchall(r"p", word)) + 0.104254*length(matchall(r"l", word)) + 0.100262*length(matchall(r"r", word)) + 0.099480*length(matchall(r"j", word)) + 0.097076*length(matchall(r"t", word)) + 0.096195*length(matchall(r"c", word)) + 0.095999*length(matchall(r"\u00fa", word)) + 0.090362*length(matchall(r"[0-9]{2}", word)) + 0.082615*length(matchall(r"\u016b", word)) + 0.080488*length(matchall(r"s", word)) + 0.075311*length(matchall(r"g", word)) + 0.075048*length(matchall(r"z", word)) + 0.067591*length(matchall(r"k", word)) + 0.065711*length(matchall(r"f", word)) + 0.065148*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd][bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.063661*length(matchall(r"a", word)) + 0.060130*length(matchall(r"y", word)) + 0.059559*length(matchall(r"\u0159", word)) + 0.056398*length(matchall(r"i", word)) + 0.054900*length(matchall(r"o", word)) + 0.050908*length(matchall(r"\u00e1", word)) + 0.048779*length(matchall(r"w", word)) + 0.046645*length(matchall(r"\u00fb", word)) + 0.034323*length(matchall(r"\u00e2", word)) + 0.033232*length(matchall(r"\u00eb", word)) + 0.031705*length(matchall(r"\u00f4", word)) + 0.029573*length(matchall(r"\u0101", word)) + 0.028180*length(matchall(r"u", word)) + 0.028180*length(matchall(r"u", word)) + 0.027809*length(matchall(r"\u00e4", word)) + 0.026002*length(matchall(r"\u00f3", word)) + 0.024175*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd]\$", word)) + 0.021481*length(matchall(r"e", word)) + 0.019389*length(matchall(r"\u0131", word)) + 0.018713*length(matchall(r"[^a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fdbcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.012112*length(matchall(r"\u00e0", word)) + 0.010956*length(matchall(r"h", word)) + 0.007262*length(matchall(r"\u00ee", word)) + 0.004981*length(matchall(r"\u00e8", word))
    elseif language == "es"
      return 0.187036 + 0.317005*length(matchall(r"\u00e3", word)) + 0.315815*length(matchall(r"\u0169", word)) + 0.292691*length(matchall(r"\u0103", word)) + 0.253129*length(matchall(r"\u011b", word)) + 0.227771*length(matchall(r"[^a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fdbcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.207797*length(matchall(r"\u0159", word)) + 0.189736*length(matchall(r"[0-9]{2}", word)) + 0.184000*length(matchall(r"\u00e6", word)) + 0.182175*length(matchall(r"\u012b", word)) + 0.167399*length(matchall(r"\u00f5", word)) + 0.139567*length(matchall(r"\u0101", word)) + 0.111823*length(matchall(r"x", word)) + 0.102212*length(matchall(r"\u016b", word)) + 0.099673*length(matchall(r"k", word)) + 0.099467*length(matchall(r"\u00fd", word)) + 0.097008*length(matchall(r"z", word)) + 0.090673*length(matchall(r"y", word)) + 0.077894*length(matchall(r"\u0131", word)) + 0.075144*length(matchall(r"p", word)) + 0.068023*length(matchall(r"j", word)) + 0.064888*length(matchall(r"f", word)) + 0.064057*length(matchall(r"t", word)) + 0.062861*length(matchall(r"c", word)) + 0.061194*length(matchall(r"s", word)) + 0.059466*length(matchall(r"o", word)) + 0.059261*length(matchall(r"d", word)) + 0.058316*length(matchall(r"w", word)) + 0.057997*length(matchall(r"g", word)) + 0.052533*length(matchall(r"a", word)) + 0.051308*length(matchall(r"r", word)) + 0.050576*length(matchall(r"i", word)) + 0.048901*length(matchall(r"b", word)) + 0.047846*length(matchall(r"v", word)) + 0.047137*length(matchall(r"q", word)) + 0.045976*length(matchall(r"[0-9]{4}", word)) + 0.043086*length(matchall(r"n", word)) + 0.042979*length(matchall(r"m", word)) + 0.040604*length(matchall(r"\u00e4", word)) + 0.039670*length(matchall(r"h", word)) + 0.039339*length(matchall(r"l", word)) + 0.038610*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd][bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.035417*length(matchall(r"e", word)) + 0.032111*length(matchall(r"\u00e1", word)) + 0.030724*length(matchall(r"^[bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]{3}", word)) + 0.023949*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd]\$", word)) + 0.021964*length(matchall(r"\u00f6", word)) + 0.021964*length(matchall(r"\u00f6", word)) + 0.014352*length(matchall(r"u", word)) + 0.014352*length(matchall(r"u", word)) + 0.000250*length(matchall(r"[0-9]", word))
    elseif language == "fr"
      return 0.094123 + 0.524550*length(matchall(r"[0-9]{4}", word)) + 0.146372*length(matchall(r"[0-9]{2}", word)) + 0.115989*length(matchall(r"\u00ef", word)) + 0.075470*length(matchall(r"j", word)) + 0.071641*length(matchall(r"w", word)) + 0.067887*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd]\$", word)) + 0.066211*length(matchall(r"[a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fd][bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.064186*length(matchall(r"g", word)) + 0.062926*length(matchall(r"k", word)) + 0.060646*length(matchall(r"y", word)) + 0.059996*length(matchall(r"x", word)) + 0.059590*length(matchall(r"f", word)) + 0.057422*length(matchall(r"c", word)) + 0.055183*length(matchall(r"\u00e7", word)) + 0.054494*length(matchall(r"r", word)) + 0.053814*length(matchall(r"z", word)) + 0.051429*length(matchall(r"t", word)) + 0.049218*length(matchall(r"s", word)) + 0.044615*length(matchall(r"\u00eb", word)) + 0.044090*length(matchall(r"i", word)) + 0.043803*length(matchall(r"d", word)) + 0.042808*length(matchall(r"\u00f6", word)) + 0.042808*length(matchall(r"\u00f6", word)) + 0.042791*length(matchall(r"b", word)) + 0.042591*length(matchall(r"q", word)) + 0.039526*length(matchall(r"p", word)) + 0.038798*length(matchall(r"v", word)) + 0.035982*length(matchall(r"\u00e9", word)) + 0.034998*length(matchall(r"o", word)) + 0.032743*length(matchall(r"[0-9]", word)) + 0.031503*length(matchall(r"a", word)) + 0.028726*length(matchall(r"[^a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fdbcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.027647*length(matchall(r"h", word)) + 0.027537*length(matchall(r"m", word)) + 0.027147*length(matchall(r"l", word)) + 0.025762*length(matchall(r"\u00f4", word)) + 0.020906*length(matchall(r"^[bcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]{3}", word)) + 0.020085*length(matchall(r"\u00e8", word)) + 0.016057*length(matchall(r"n", word)) + 0.014943*length(matchall(r"\u00e2", word)) + 0.011852*length(matchall(r"u", word)) + 0.011852*length(matchall(r"u", word)) + 0.008881*length(matchall(r"\u00e0", word)) + 0.006535*length(matchall(r"e", word)) + 0.003959*length(matchall(r"\u00ea", word))
    elseif language == "it"
      return 0.216031 + 0.280613*length(matchall(r"[0-9]{2}", word)) + 0.219277*length(matchall(r"x", word)) + 0.149924*length(matchall(r"[0-9]", word)) + 0.145241*length(matchall(r"[^a\u00e2\u00e1\u00e0\u00e4\u01ce\u0103\u00e3\u0101\u00e6\u01e3e\u00ea\u00e9\u00e8\u00eb\u011b\u0115\u0113i\u00ef\u00ed\u00ee\u01d0\u012d\u0129\u0131\u012bo\u00f6\u00f3\u00f4\u00f6\u01d2\u014f\u00f5u\u00fa\u00f9\u00fbu\u01d4\u016d\u0169\u016by\u00fdbcdfghjklmnpqrstvwxz\u00f1\u00e7\u0159]", word)) + 0.115833*length(matchall(r"z", word)) + 0.104811*length(matchall(r"c", word)) + 0.104514*length(matchall(r"p", word)) + 0.101104*length(matchall(r"t", word)) + 0.096837*length(matchall(r"k", word)) + 0.094215*length(matchall(r"q", word)) + 0.092929*length(matchall(r"f", word)) + 0.091644*length(matchall(r"s", word)) + 0.075643*length(matchall(r"n", word)) + 0.073194*length(matchall(r"g", word)) + 0.071579*length(matchall(r"y", word)) + 0.067655*length(matchall(r"j", word)) + 0.066069*length(matchall(r"b", word)) + 0.064722*length(matchall(r"e", word)) + 0.059960*length(matchall(r"v", word)) + 0.058603*length(matchall(r"i", word)) + 0.057001*length(matchall(r"m", word)) + 0.054888*length(matchall(r"w", word)) + 0.053622*length(matchall(r"o", word)) + 0.052965*length(matchall(r"d", word)) + 0.052437*length(matchall(r"a", word)) + 0.051798*length(matchall(r"l", word)) + 0.051058*length(matchall(r"\u00e9", word)) + 0.050466*length(matchall(r"\u00e1", word)) + 0.049816*length(matchall(r"r", word)) + 0.049440*length(matchall(r"\u00f9", word)) + 0.048566*length(matchall(r"\u00fa", word)) + 0.044918*length(matchall(r"\u00e2", word)) + 0.034806*length(matchall(r"\u00f1", word)) + 0.031362*length(matchall(r"u", word)) + 0.031362*length(matchall(r"u", word)) + 0.028077*length(matchall(r"\u00f3", word)) + 0.023515*length(matchall(r"\u00ea", word)) + 0.013186*length(matchall(r"\u00f4", word))
    elseif language == "ja"
      return 0.192934 + 0.401897*length(matchall(r"\uff57", word)) + 0.391781*length(matchall(r"\uff37", word)) + 0.345174*length(matchall(r"\uff16", word)) + 0.337752*length(matchall(r"\uff17", word)) + 0.335693*length(matchall(r"\uff18", word)) + 0.305787*length(matchall(r"\uff19", word)) + 0.284248*length(matchall(r"\uff13", word)) + 0.260788*length(matchall(r"\uff14", word)) + 0.250454*length(matchall(r"\uff32", word)) + 0.249550*length(matchall(r"\uff52", word)) + 0.239987*length(matchall(r"\uff48", word)) + 0.232954*length(matchall(r"\uff15", word)) + 0.224712*length(matchall(r"\uff28", word)) + 0.201113*length(matchall(r"\uff4d", word)) + 0.198311*length(matchall(r"\uff56", word)) + 0.197385*length(matchall(r"\uff12", word)) + 0.195817*length(matchall(r"\uff23", word)) + 0.194144*length(matchall(r"\uff2c", word)) + 0.191657*length(matchall(r"\uff47", word)) + 0.187868*length(matchall(r"\uff4e", word)) + 0.183400*length(matchall(r"\uff27", word)) + 0.181215*length(matchall(r"\uff50", word)) + 0.177365*length(matchall(r"\uff2d", word)) + 0.175796*length(matchall(r"\uff34", word)) + 0.175779*length(matchall(r"\uff11", word)) + 0.174960*length(matchall(r"\uff42", word)) + 0.172881*length(matchall(r"\uff49", word)) + 0.171703*length(matchall(r"\uff43", word)) + 0.171623*length(matchall(r"\uff4c", word)) + 0.168697*length(matchall(r"\uff53", word)) + 0.166248*length(matchall(r"\uff54", word)) + 0.162419*length(matchall(r"\uff25", word)) + 0.161625*length(matchall(r"\uff2a", word)) + 0.159372*length(matchall(r"\uff22", word)) + 0.158361*length(matchall(r"\uff55", word)) + 0.158059*length(matchall(r"\uff24", word)) + 0.156341*length(matchall(r"\uff41", word)) + 0.153941*length(matchall(r"\uff45", word)) + 0.153059*length(matchall(r"\uff39", word)) + 0.149345*length(matchall(r"\uff33", word)) + 0.147929*length(matchall(r"\uff2e", word)) + 0.146199*length(matchall(r"\uff46", word)) + 0.144357*length(matchall(r"\uff35", word)) + 0.144285*length(matchall(r"\uff44", word)) + 0.134242*length(matchall(r"\uff21", word)) + 0.132635*length(matchall(r"\uff26", word)) + 0.129675*length(matchall(r"\uff29", word)) + 0.122793*length(matchall(r"\uff4b", word)) + 0.122485*length(matchall(r"\uff2b", word)) + 0.122419*length(matchall(r"\uff30", word)) + 0.122348*length(matchall(r"\uff4f", word)) + 0.117883*length(matchall(r"\uff36", word)) + 0.116234*length(matchall(r"\uff59", word)) + 0.110487*length(matchall(r"^[\u4E00-\u9FFF]", word)) + 0.104395*length(matchall(r"\u304f", word)) + 0.100524*length(matchall(r"\u30b6", word)) + 0.099742*length(matchall(r"\u30ba", word)) + 0.095281*length(matchall(r"\u5cf6", word)) + 0.094178*length(matchall(r"\u30ab", word)) + 0.094091*length(matchall(r"\u308f", word)) + 0.088825*length(matchall(r"\u30bc", word)) + 0.086408*length(matchall(r"\u30b5", word)) + 0.086084*length(matchall(r"[\u4E00-\u9FFF]\$", word)) + 0.083627*length(matchall(r"\u30dd", word)) + 0.082973*length(matchall(r"\uff2f", word)) + 0.082004*length(matchall(r"\u304c", word)) + 0.081355*length(matchall(r"\u30bb", word)) + 0.080537*length(matchall(r"\u56fd", word)) + 0.080233*length(matchall(r"\u90ce", word)) + 0.076580*length(matchall(r"\u30b9", word)) + 0.071712*length(matchall(r"\u30db", word)) + 0.071397*length(matchall(r"\u30cb", word)) + 0.070678*length(matchall(r"\u30b3", word)) + 0.070540*length(matchall(r"\u30cf", word)) + 0.069523*length(matchall(r"\u305f", word)) + 0.066932*length(matchall(r"\u30d1", word)) + 0.066558*length(matchall(r"\u7acb", word)) + 0.066497*length(matchall(r"\u30c8", word)) + 0.065144*length(matchall(r"\u30bf", word)) + 0.065009*length(matchall(r"\u308d", word)) + 0.064780*length(matchall(r"\u3068", word)) + 0.064771*length(matchall(r"\u3064", word)) + 0.063986*length(matchall(r"\u30af", word)) + 0.062007*length(matchall(r"\u5357", word)) + 0.061800*length(matchall(r"\u30bd", word)) + 0.060136*length(matchall(r"\u30e4", word)) + 0.059696*length(matchall(r"\u307e", word)) + 0.059586*length(matchall(r"\u30d9", word)) + 0.059112*length(matchall(r"\u30ef", word)) + 0.058790*length(matchall(r"\u3084", word)) + 0.058416*length(matchall(r"\u30b0", word)) + 0.058322*length(matchall(r"\u5ddd", word)) + 0.058256*length(matchall(r"\u30ad", word)) + 0.058247*length(matchall(r"\u30ea", word)) + 0.057527*length(matchall(r"\u30e1", word)) + 0.057262*length(matchall(r"\u30c9", word)) + 0.057210*length(matchall(r"\u5c71", word)) + 0.056999*length(matchall(r"\u30cc", word)) + 0.056670*length(matchall(r"\u30e0", word)) + 0.056596*length(matchall(r"\u30d3", word)) + 0.056482*length(matchall(r"\u672c", word)) + 0.055207*length(matchall(r"\u30d4", word)) + 0.055031*length(matchall(r"\u30c0", word)) + 0.054831*length(matchall(r"\u4e2d", word)) + 0.054312*length(matchall(r"\u305b", word)) + 0.053996*length(matchall(r"\u3053", word)) + 0.053672*length(matchall(r"\u30b7", word)) + 0.053307*length(matchall(r"\u30cd", word)) + 0.053183*length(matchall(r"\u3061", word)) + 0.053151*length(matchall(r"\u30ed", word)) + 0.053137*length(matchall(r"\u30fc", word)) + 0.052671*length(matchall(r"\u30b8", word)) + 0.052482*length(matchall(r"\u30ce", word)) + 0.052469*length(matchall(r"\u30df", word)) + 0.052218*length(matchall(r"\u3059", word)) + 0.051149*length(matchall(r"\u30d0", word)) + 0.051120*length(matchall(r"\u30c1", word)) + 0.050576*length(matchall(r"\u3055", word)) + 0.050530*length(matchall(r"\u9ad8", word)) + 0.050406*length(matchall(r"\u3051", word)) + 0.050285*length(matchall(r"\u30d5", word)) + 0.049924*length(matchall(r"\u30b2", word)) + 0.049910*length(matchall(r"\u3057", word)) + 0.049552*length(matchall(r"\u30d2", word)) + 0.048954*length(matchall(r"\u304d", word)) + 0.048841*length(matchall(r"\u30e2", word)) + 0.047662*length(matchall(r"\u306a", word)) + 0.046810*length(matchall(r"\u30d7", word)) + 0.046802*length(matchall(r"\u306e", word)) + 0.046168*length(matchall(r"\u3046", word)) + 0.045981*length(matchall(r"\u30f3", word)) + 0.045687*length(matchall(r"\u3089", word)) + 0.045390*length(matchall(r"\u30ec", word)) + 0.045015*length(matchall(r"\u30ac", word)) + 0.044927*length(matchall(r"\u30da", word)) + 0.044909*length(matchall(r"\u884c", word)) + 0.043977*length(matchall(r"\u30de", word)) + 0.043935*length(matchall(r"\u30f4", word)) + 0.043439*length(matchall(r"\u30c4", word)) + 0.042776*length(matchall(r"\u307f", word)) + 0.042713*length(matchall(r"\u30ca", word)) + 0.041510*length(matchall(r"\u30c3", word)) + 0.039911*length(matchall(r"\u30e9", word)) + 0.039382*length(matchall(r"\u30ae", word)) + 0.036680*length(matchall(r"\u5317", word)) + 0.034881*length(matchall(r"\u30b1", word)) + 0.034862*length(matchall(r"\u30eb", word)) + 0.033453*length(matchall(r"\u539f", word)) + 0.033265*length(matchall(r"\u65b0", word)) + 0.031582*length(matchall(r"^[\u3040-\u30FA\uFF66-\uFF9D]{3}", word)) + 0.031414*length(matchall(r"\u795e", word)) + 0.030574*length(matchall(r"\u30d6", word)) + 0.030494*length(matchall(r"\u30dc", word)) + 0.030311*length(matchall(r"\u3063", word)) + 0.030213*length(matchall(r"\u30c6", word)) + 0.029947*length(matchall(r".", word)) + 0.029441*length(matchall(r"[\u4E00-\u9FFF]", word)) + 0.027448*length(matchall(r"\u3093", word)) + 0.026703*length(matchall(r"\u3052", word)) + 0.026097*length(matchall(r"\u308a", word)) + 0.025692*length(matchall(r"\u3081", word)) + 0.024119*length(matchall(r"\u3044", word)) + 0.023380*length(matchall(r"\u30a2", word)) + 0.022242*length(matchall(r"\u3058", word)) + 0.021137*length(matchall(r"\u4e0a", word)) + 0.019239*length(matchall(r"\u30a6", word)) + 0.018306*length(matchall(r"\u30c7", word)) + 0.017776*length(matchall(r"\u6b63", word)) + 0.017477*length(matchall(r"\u9577", word)) + 0.013000*length(matchall(r"\u5e73", word)) + 0.012673*length(matchall(r"\u30b4", word)) + 0.009949*length(matchall(r"\u6771", word)) + 0.009247*length(matchall(r"\u897f", word)) + 0.006630*length(matchall(r"\u30a8", word)) + 0.006460*length(matchall(r"[^\u4E00-\u9FFF\u3040-\u30FA\uFF66-\uFF9D]", word))
  end 
end


"""
  `spoken_length(str, language="en-US")`
  
  Estimates the time in seconds that it would take to say a piece of text.

  Credit for this algorithm should go to [Hal Daumé III](http://nlpers.blogspot.co.uk/2015/09/how-longll-it-take-to-say-that.html).
  The implementation here is based on his Python implementation. In short, the
  algorithm finds certain features using regular expressions and assigns a weight 
  to each of them, based on data collected during experiments with speech synthesis
  software, with some modification for inter-word gaps. 
"""
function spoken_length(str::String, language::String="en-US")

  languages = ["en-us", "de", "fr", "it", "es", "ja"]
  if ! (lowercase(language) in languages)
    error("Requested language '$language' is not supported.")
  end
  
  #Divvy our string.
  words = split(str)
  
  #
  time = -0.116751 + 0.099640 * length(words)

  for word in words
    time += 0.691677 * time_word(word, language)
  end

  #sanity check output
  if time < 0
    return 0
  else
    return time
  end
end

export spoken_length, syllable_count
